package cn.com.greatwall.common.utils;

import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator;

import cn.com.greatwall.common.exception.BadRequestException;
import cn.hutool.core.util.ObjectUtil;

/**
 * @Author herw
 * @Time 2020-06-26 8:36:20 PM
 * @Version 1.0
 * @Description: 验证工具
 */
public class ValidationUtil {
    /**
     * 验证空
     * 
     * @param obj
     * @param entity
     * @param parameter
     * @param value
     */
    public static void isNull(Object obj, String entity, String parameter, Object value) {
        if (ObjectUtil.isNull(obj)) {
            String msg = entity + " 不存在：" + parameter + " is" + value;
            throw new BadRequestException(msg);
        }
    }
    
    /**
     * 验证是否为邮箱
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        return new EmailValidator().isValid(email, null);
    }
}
